16.9 C
New York
Friday, March 28, 2025
Home Blog Page 7

ios – How do I re-use code that pulls onto a macOS GraphicsContext to attract onto an UIKit context?


The completely different coordinate programs of Cocoa and UIKit trigger downside when drawing a string in a UIGraphicsContext.

I’ve written code for macOS, the place I draw a mixture of primitives, attributedText, and single CGGlyphs onto a CGContext. Subsequently I first create a container object that holds a number of arrays of objects. These objects verify to a protocol DrawingContent. The one protocol requirement is a technique .draw(inContext: CGContext).

My customized NSView is holding such a container, and the view’s draw methodology then iterates over the container parts, calling their .draw methodology with the present CGContext. I’ve stripped the code right down to the minimal and can present it on the finish of this query. The results of the pattern code earlier than being flipped appears to be like like this:

Result of original code

My precise code is far more complicated, because the objects to be drawn are a results of a number of algorithms. The rationale I put the objects right into a container is that from the beginning on I meant to additionally create an iOS model, so the outcomes of the required calculations first go right into a framework-agnostic summary class. I used to be conscious of the truth that UIKit Views use a flipped coordinate system and that I ultimately must take care of that. Now I’m trying to put in writing the iOS model – and I’m at a loss.

The preliminary outcome once I simply name the code with none alteration from an UIView appears to be like like this:

result of flipped coordinate system

This was – type of – anticipated, though the textual content not being flipped is odd. So to flip the entire imagery I set a CGAffineTransform to the context earlier than passing it to the drawing container like this:

currentContext.translateBy(x: 0, y: rect.peak)
currentContext.scaleBy(x: 1, y: -1)

The outcome appears to be like like this:

result of flipped system transformed back

As you possibly can see the canvas is flipped as anticipated, however, sadly, the AttributedString is drawn the other way up. Apparently, although, the only CGGlyph, though utilizing the identical font, is drawn accurately.

WHAT I HAVE TRIED SO FAR:

  1. Solutions to related questions recommend to use n CGAffineTransform to the contexts’s textMatrix (along with the context itself). This causes the CGGlyph (which had been drawn accurately) now to be the other way up and at a unsuitable location, whereas the AttributedText stays untouched.

  2. In one other place it was advised to briefly flip the context only for the drawing of the string like this:

context.saveGState()
context.scaleBy(x: 1, y: -1)
context.translateBy(x: 0, y: -bounds.peak)
// draw string right here...
context.restoreGState()

The issue with that is, that the container doesn’t know in regards to the body’s peak. Once I (for testing) hardcode the peak the textual content now attracts accurately, however at its „authentic“ unsuitable place on the prime of the view. The 2 similar transformations clearly cancel out one another.

  1. I additionally tried to manually apply the scaling and tranlating to the y-position of the textual content, along with what I did in step 2. This revealed one other downside: The textual content now exhibits at about the appropriate place, however not fairly: It now dangles from the imaginary baseline as an alternative of sitting on it.
    I additionally need to state, that even when I’d learn the way the font metrics come into play right here, making use of this to my precise code can be an amazing quantity of labor, as – as said – the drawing strategies of my objects have no idea the peak of the view they attract, so I might must move that as an extra argument, and – most significantly – I must write all of that scaling and translating conditionally when compiling for iOS – which might counteract my strategy to maintain the container-code framework-agnostic.

I may go down two completely different fundamental routes:

  1. I may rewrite my whole code to work within the flipped coordinate system of iOS, and for macOS I set the .isFlipped parameter on my customized NSView to return true. This is able to contain numerous work, and it nonetheless wouldn’t clear up the issue of the AttributedStrings being the other way up.

  2. I proceed looking for a option to flip EVERYTHING on the canvas.
    I would like the second route, clearly.

QUESTION:

How do I draw Objects, which can be positioned for a cartesian coordinate system (like Cocoa/Quartz 2D makes use of), right into a CGContext that makes use of a flipped coodinate system (like UIKIT does), so that each one objects of various varieties (primitives, Glyphs and Strings) are drawn on the appropriate place and within the appropriate orientation?

Right here is my code. For comfort, as an alternative of displaying the UIView code I present a self containing model for macOS with the NSView set to .isFlipped – the behaviour is – so far as I may study – precisely the identical.

import AppKit

public protocol DrawingContent {
    func draw(inContext context: CGContext)
}

public struct TestPath: DrawingContent {
    
    public func draw(inContext context: CGContext) {
        
        context.beginPath()
        context.setLineWidth(CGFloat(2))
        context.transfer(to: CGPoint(x: 200, y: 30))
        context.addLine(to: CGPoint(x: 250, y: 30))
        context.addLine(to: CGPoint(x: 250, y: 60))
        context.addLine(to: CGPoint(x: 230, y: 60))
        context.strokePath()
    }
}

public struct TestText: DrawingContent {
    
    public func draw(inContext context: CGContext) {
      
        let font = CTFontCreateWithName("Helvetica" as CFString, 24, nil)
        
        var attributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.font : font,
            NSAttributedString.Key.foregroundColor : NSColor.black]
        let attributedText = NSAttributedString(string: "Testtext", attributes: attributes)
        let descender = CTFontGetDescent(font)
        let textOrigin = CGPoint(x: 100, y: (30-descender))
        attributedText.draw(at: textOrigin)
    }
}

public struct TestGlyph: DrawingContent {
    
    public func draw(inContext context: CGContext) {
        
        var font = CTFontCreateWithName("Helvetica" as CFString, 24, nil)
        var place = CGPoint(x: 30, y: 30)
        var glyph = CGGlyph(36) // Capital Letter A
        CTFontDrawGlyphs(font, &glyph, &place, 1, context)
    }
}

public class FlippedTestView: NSView {
    
    var drawingContent: [DrawingContent]
    
    override public var isFlipped: Bool {return true}
    
    override public init(body: CGRect)  {
        let drawingContent: [DrawingContent] = [TestGlyph(), TestText(), TestPath()]
        self.drawingContent = drawingContent
        tremendous.init(body: body)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been carried out")
    }
    
    override open func draw(_ rect: CGRect) {
        
        let currentContext = NSGraphicsContext.present!.cgContext
        currentContext.translateBy(x: 0, y: rect.peak)
        currentContext.scaleBy(x: 1, y: -1)
        
        for factor in drawingContent {
            factor.draw(inContext: currentContext)
        }
    }
}

@major
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet var window: NSWindow!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code right here to initialize your utility
        
        let testView = FlippedTestView(body: CGRect(x: 0, y: 0, width: 300, peak: 100))
        
        self.window.contentView = testView
        self.window.setFrame(CGRect(x: 200, y: 200, width: 300, peak: 100), show: true)
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code right here to tear down your utility
    }

    func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
        return true
    }
}

APT36 Spoofs India Put up Web site to Infect Home windows and Android Customers with Malware

0


Mar 27, 2025Ravie LakshmananCell Safety / Malware

APT36 Spoofs India Put up Web site to Infect Home windows and Android Customers with Malware

A sophisticated persistent menace (APT) group with ties to Pakistan has been attributed to the creation of a faux web site masquerading as India’s public sector postal system as a part of a marketing campaign designed to contaminate each Home windows and Android customers within the nation.

Cybersecurity firm CYFIRMA has attributed the marketing campaign with medium confidence to a menace actor known as APT36, which is also called Clear Tribe.

The fraudulent web site mimicking India Put up is called “postindia[.]web site.” Customers who land on the location from Home windows methods are prompted to obtain a PDF doc, whereas these visiting from an Android gadget are served a malicious software package deal (“indiapost.apk”) file.

Cybersecurity

“When accessed from a desktop, the location delivers a malicious PDF file containing ‘ClickFix‘ ways,” CYFIRMA mentioned. “The doc instructs customers to press the Win + R keys, paste a offered PowerShell command into the Run dialog, and execute it – doubtlessly compromising the system.”

An evaluation of the EXIF knowledge related to the dropped PDF exhibits that it was created on October 23, 2024, by an writer named “PMYLS,” a possible reference to Pakistan’s Prime Minister Youth Laptop computer Scheme. The area impersonating India Put up was registered a few month afterward November 20, 2024.

India Post Website

The PowerShell code is designed to obtain a next-stage payload from a distant server (“88.222.245[.]211”) that is presently inactive.

Alternatively, when the identical web site is visited from an Android gadget, it urges customers to put in their cell app for a “higher expertise.” The app, as soon as put in, requests in depth permissions that permit it to reap and exfiltrate delicate knowledge, together with contact lists, present location, and information from exterior storage.

Cybersecurity

“The Android app adjustments its icon to imitate a non-suspicious Google Accounts icon to hide its exercise, making it troublesome for the person to find and uninstall the app after they need to take away it,” the corporate mentioned. “The app additionally has a function to drive customers to just accept permissions if they’re denied within the first occasion.”

The malicious app can also be designed to run within the background repeatedly even after a tool restart, whereas explicitly searching for permissions to disregard battery optimization.

“ClickFix is more and more being exploited by cybercriminals, scammers, and APT teams, as reported by different researchers observing its use within the wild,” CYFIRMA mentioned. “This rising tactic poses a major menace as it may well goal each unsuspecting and tech-savvy customers who might not be conversant in such strategies.”

Discovered this text fascinating? Observe us on Twitter and LinkedIn to learn extra unique content material we put up.



Classiscam Operators Use Automated Malicious Websites to Steal Monetary Information

0


Classiscam, an automatic scam-as-a-service operation, has been recognized as a big menace in Central Asia, leveraging subtle strategies to defraud customers of on-line marketplaces and e-commerce platforms.

This fraudulent scheme, highlighted within the Excessive-Tech Crime Tendencies Report 2025, makes use of Telegram bots to generate faux web sites that mimic legit companies, successfully deceiving victims into sharing their monetary particulars.

Anatomy of the Rip-off

The Classiscam operation usually begins with fraudsters posing as patrons on on-line marketplaces.

 Financial Data Financial Data
fraudster on the web market

They provoke contact with legit sellers and persuade them to proceed communications on Telegram, shifting the dialog to a much less safe surroundings.

As soon as on Telegram, the scammers introduce a faux supply service, full with a phishing web site that carefully resembles respected logistics platforms.

These phishing websites are designed to accumulate delicate data similar to login credentials, banking card numbers, and different monetary information.

The fraudsters typically present faux proof of cost or supply invoices to construct belief and persuade sellers to proceed with the transaction.

Unaware of the deception, many sellers unknowingly present their monetary data, leading to unauthorized transactions and theft.

Technical Infrastructure and Methodology

The technical sophistication of Classiscam is clear in its use of Telegram bots for producing phishing hyperlinks.

One such group, often called Namangun Workforce, affords a variety of choices for creating faux pages concentrating on particular international locations and companies.

The bot offers ready-made phishing hyperlinks which can be distributed throughout social networks.

Evaluation of the phishing websites reveals a number of key functionalities:

  1. Pretend login types designed to reap usernames and passwords.
  2. IP handle monitoring for person session monitoring.
  3. Picture add mechanisms to gather further paperwork or images.
  4. Repeated AJAX calls simulating buyer assist interactions.

The scammers additionally make use of API companies, such because the “Falcon” API, which permits for the connection of customized servers or Telegram bots to generate faux web sites.

In accordance with the Report, this infrastructure allows the fast creation and deployment of convincing phishing pages throughout a number of domains.

As on-line platforms proceed to achieve recognition in growing international locations, notably in Central Asia, the menace posed by Classiscam and comparable operations is prone to develop.

Customers and companies alike should stay vigilant and undertake strong safety practices to guard themselves from these more and more subtle and automatic scams.

Are you from SOC/DFIR Groups? – Analyse Malware, Phishing Incidents & get stay Entry with ANY.RUN -> Begin Now for Free

Initiative hopes to ship {industry} transition to sustainable polymers



Initiative hopes to ship {industry} transition to sustainable polymers

A brand new initiative that seeks to scale back the environmental affect of thousands and thousands of family and industrial chemical substances was introduced on 26 March, bringing collectively specialists from a few of the world’s greatest corporations – together with Unilever and the world’s greatest chemical substances firm BASF – in addition to main lecturers, commerce associations, analysis institutes and policymakers.

The hassle is being spearheaded by the Royal Society of Chemistry.

Polymers in liquid formulations (PLFs) are key substances present in a variety of merchandise, from paints, coatings and water remedy, to cosmetics, private care and family cleansing merchandise. Members of the brand new Sustainable PLFs 2040 initiative will collaborate to revolutionise the way in which PLFs are made, used and disposed of by 2040.

These PLFs are price $125 billion annually and are important to creating thousands and thousands of merchandise work – however virtually not one of the 36 million tonnes of those close to ubiquitous chemical substances are recovered or recycled after use.

Professor Anju Massey-Brooker from the Royal Society of Chemistry, mentioned: “We encounter PLFs each single day, however when it comes to analysis and improvement they’re the ‘forgotten’ group of polymers. There may be an pressing have to make them extra sustainable by creating biodegradable alternate options and creating round economic system infrastructure to cease the waste of those beneficial chemical substances, which in lots of instances, go immediately down the plughole.

“We can not overstate the size of the problem – so it’s large to have so most of the world’s largest producers and customers of those chemical substances committing their experience and useful resource to assist clear them up and create new instruments and information that may profit enterprise, the atmosphere and society as an entire.”

Below the brand new formal construction of the Sustainable PLFs 2040 initiative, a foresight and coordination group will likely be answerable for overseeing supply in opposition to a roadmap beforehand revealed by the RSC. The group will collaborate throughout sectors whereas fostering inclusive decision-making, and driving coordinated actions that result in long-term, sustainable change.

The group is initially comprised of: Professor Anju Massey Brooker from the Royal Society of Chemistry; Professor Andreas Künkel and Dr Martin Klatt from the world’s greatest chemical substances firm, BASF; Dr Paul Jenkins from Unilever; former RSC president, Professor Gill Reid from the College of Southampton; Professor Matthew Davidson from the College of Bathtub; Dr Jen Vanderhoven from the BBIA; and Dr Damian Kelly from Croda.

Foresight and coordination group member and RSC past-president Professor Gill Reid mentioned: “This can be a actually thrilling space for innovation, and the Royal Society of Chemistry’s distinctive method will likely be instrumental in delivering actual, tangible outcomes—from pioneering analysis to market-ready merchandise. The emphasis on creating sustainability evaluation and reporting instruments which are accessible to all on a pre-competitive foundation is especially promising, as it can empower industry-wide progress and speed up the transition to a extra sustainable future by 2040.”

Dr Damian Kelly from chemical substances firm Croda mentioned: “Polymers for liquid formulations signify a critically essential class of chemical merchandise which are important substances in many alternative liquid formulations throughout numerous finish functions. Polymers have traditionally been developed to ship a cheap particular efficiency inside a formulation with little consideration given to how they’re produced or what occurs to them as soon as they’ve served their objective.”

The Sustainable PLFs 2040 initiative will deliver collectively main corporations working throughout the provision chains with the aptitude to develop, scale and commercialise novel polymers with considerably improved environmental credentials.”

The launch of the Sustainable PLFs 2040 initiative is the most recent step in ongoing work first began in 2017. Eager to use classes realized from enhancing the sustainability of plastics use, in 2021 the RSC shaped the Sustainable PLFs Job Power to chart a path ahead for this group of non-plastic polymers. The top end result was the creation of a devoted roadmap to information a metamorphosis within the chemical industries from producing fossil gas derived PLFs to sustainable PLFs by 2040.

Central to the roadmap are two missions to develop and scale biodegradable PLFs by 2030 and advance round economic system infrastructure for PLFs by 2030, each of which is able to catalyse the transition to sustainable PLFs by 2040.

For extra details about the Sustainable PLFs 2040 initiative, go to: https://www.rsc.org/news-events/articles/2025/03-march/Sustainable-PLFs-Initiative-2040

Phishing Stays the Most Prevalent Cyber Menace

0


Impactful Parts of Phishing ScamINKY has revealed its annual report on electronic mail safety, discovering that phishing accounted for 30% of all reported cybercrimes final 12 months.