Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

win32-def

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

win32-def - npm Package Compare versions

Comparing version 17.2.1 to 18.0.0

4

dist/lib/fixed-buffer.d.ts

@@ -9,3 +9,3 @@ /// <reference types="node" resolution-mode="require"/>

*/
export declare function wcharBuffer(length: number): StringBuffer;
export declare function wcharBuffer(charLength: number): StringBuffer;
/**

@@ -20,2 +20,2 @@ * Fixed length "Buffer" type, for use in Struct type definitions.

*/
export declare function BufferTypeFactory(length: number, encoding?: BufferEncoding): StringBuffer;
export declare function BufferTypeFactory(byteLength: number, encoding?: BufferEncoding): StringBuffer;

@@ -10,5 +10,5 @@ import assert from 'assert';

*/
export function wcharBuffer(length) {
assert(length >= 0);
return BufferTypeFactory(length * 2, 'ucs2');
export function wcharBuffer(charLength) {
assert(charLength >= 0);
return BufferTypeFactory(charLength * 2, 'ucs2');
}

@@ -24,4 +24,4 @@ /**

*/
export function BufferTypeFactory(length, encoding) {
assert(length >= 0);
export function BufferTypeFactory(byteLength, encoding) {
assert(byteLength >= 0);
const inst = Object.create(types.byte, {

@@ -38,3 +38,3 @@ constructor: {

writable: false,
value: length,
value: byteLength,
},

@@ -41,0 +41,0 @@ encoding: {

@@ -0,5 +1,23 @@

import { Def } from './def.enum.js';
import { StructDefType, StructTypeConstructor } from './ffi.types.js';
export declare function UnionType<T extends StructDefType>(input: T): StructTypeConstructor<T>;
export declare function UnionFactory<T>(input: StructDefType): T;
export declare function StructType<T extends StructDefType>(input: T): StructTypeConstructor<T>;
export declare function StructFactory<T>(input: StructDefType): T;
export declare const defaultStructCharOptions: Required<StructCharOptions>;
export declare function StructType<T extends StructDefType>(input: T, options?: StructCharOptions): StructTypeConstructor<T>;
export declare function StructFactory<T>(input: StructDefType, options?: StructCharOptions): T;
export interface StructCharOptions {
/**
* @default true
* @description convert property of Struct from POINTER(like LPSTR, LPWSTR) to StringBuffer,
* **Note: typeof value may be WCHAR_String instead of _POINTER**
*/
useStringBuffer?: boolean;
/**
* @default 1024
*/
maxCharLength?: number;
/**
* @default [LPMSG, LPSTR, LPWSTR, LPTSTR, LPWORD ]
*/
CharDefs?: Def[];
}

@@ -5,2 +5,4 @@ /* eslint-disable import/no-extraneous-dependencies */

import UnionDi from 'ref-union-di';
import { LPMSG, LPSTR, LPTSTR, LPWORD, LPWSTR } from './common.def.js';
import { wcharBuffer } from './fixed-buffer.js';
// const UnionDi = _UnionDi

@@ -16,11 +18,43 @@ const Union = UnionDi(ref);

}
export const defaultStructCharOptions = {
useStringBuffer: true,
maxCharLength: 1024,
CharDefs: [
LPMSG,
LPSTR,
LPWSTR,
LPTSTR,
LPWORD,
],
};
const Struct = StructDi(ref);
export function StructType(input) {
export function StructType(input, options) {
const initType = genInitTyp(input, options);
// @ts-expect-error
return Struct(input);
return Struct(initType);
}
export function StructFactory(input) {
export function StructFactory(input, options) {
const initType = genInitTyp(input, options);
// @ts-expect-error
return new Struct(input)();
return new Struct(initType)();
}
function genInitTyp(input, options) {
const opts = {
...defaultStructCharOptions,
...options,
};
const initType = {};
Object.entries(input).forEach(([key, value]) => {
if (opts.useStringBuffer
&& typeof value === 'string'
&& opts.CharDefs.includes(value)) {
initType[key] = wcharBuffer(opts.maxCharLength);
}
else {
// @TODO recursive convertion
initType[key] = value;
}
});
return initType;
}
//# sourceMappingURL=helper.js.map

@@ -1,2 +0,2 @@

import { _POINTER, StructInstanceBase, LPTSTR, ACCESS_MASK, DWORD } from '../common.types.js';
import { _POINTER, StructInstanceBase, ACCESS_MASK, DWORD, WCHAR_String } from '../common.types.js';
import { DEVMODEW } from './wingdi.types.js';

@@ -11,3 +11,3 @@ /**

*/
pDatatype: LPTSTR;
pDatatype: WCHAR_String;
/**

@@ -36,6 +36,6 @@ * Pointer to a DEVMODE structure that identifies the default environment and initialization data for a printer.

Flags: DWORD;
pDescription: LPTSTR;
pName: LPTSTR;
pComment: LPTSTR;
pDescription: WCHAR_String;
pName: WCHAR_String;
pComment: WCHAR_String;
}
export declare type PPRINTER_INFO_1 = _POINTER;
{
"name": "win32-def",
"author": "waiting",
"version": "17.2.1",
"version": "18.0.0",
"description": "win32 definitions for node-ffi",

@@ -99,3 +99,3 @@ "keywords": [

},
"gitHead": "dfd8b49b1f56de38d94d8b51431c025cae2a45a0"
"gitHead": "6a3fc4cb2a78a2121adc43fc1dd63646b963d377"
}

@@ -14,5 +14,5 @@ import assert from 'assert'

*/
export function wcharBuffer(length: number): StringBuffer {
assert(length >= 0)
return BufferTypeFactory(length * 2, 'ucs2')
export function wcharBuffer(charLength: number): StringBuffer {
assert(charLength >= 0)
return BufferTypeFactory(charLength * 2, 'ucs2')
}

@@ -30,4 +30,4 @@

*/
export function BufferTypeFactory(length: number, encoding?: BufferEncoding): StringBuffer {
assert(length >= 0)
export function BufferTypeFactory(byteLength: number, encoding?: BufferEncoding): StringBuffer {
assert(byteLength >= 0)

@@ -46,3 +46,3 @@ const inst = Object.create(types.byte, {

writable: false,
value: length,
value: byteLength,
},

@@ -49,0 +49,0 @@

@@ -6,3 +6,6 @@ /* eslint-disable import/no-extraneous-dependencies */

import { LPMSG, LPSTR, LPTSTR, LPWORD, LPWSTR } from './common.def.js'
import { Def } from './def.enum.js'
import { StructDefType, StructTypeConstructor } from './ffi.types.js'
import { wcharBuffer } from './fixed-buffer.js'

@@ -21,11 +24,69 @@

export const defaultStructCharOptions: Required<StructCharOptions> = {
useStringBuffer: true,
maxCharLength: 1024,
CharDefs: [
LPMSG,
LPSTR,
LPWSTR,
LPTSTR,
LPWORD,
],
}
const Struct = StructDi(ref)
export function StructType<T extends StructDefType>(input: T): StructTypeConstructor<T> {
export function StructType<T extends StructDefType>(
input: T,
options?: StructCharOptions,
): StructTypeConstructor<T> {
const initType = genInitTyp(input, options)
// @ts-expect-error
return Struct(input)
return Struct(initType)
}
export function StructFactory<T>(input: StructDefType): T {
export function StructFactory<T>(input: StructDefType, options?: StructCharOptions): T {
const initType = genInitTyp(input, options)
// @ts-expect-error
return new Struct(input)() as unknown as T
return new Struct(initType)() as unknown as T
}
function genInitTyp(input: StructDefType, options?: StructCharOptions): StructDefType {
const opts: Required<StructCharOptions> = {
...defaultStructCharOptions,
...options,
}
const initType = {} as StructDefType
Object.entries(input).forEach(([key, value]) => {
if (opts.useStringBuffer
&& typeof value === 'string'
&& opts.CharDefs.includes(value)) {
initType[key] = wcharBuffer(opts.maxCharLength)
}
else {
// @TODO recursive convertion
initType[key] = value
}
})
return initType
}
export interface StructCharOptions {
/**
* @default true
* @description convert property of Struct from POINTER(like LPSTR, LPWSTR) to StringBuffer,
* **Note: typeof value may be WCHAR_String instead of _POINTER**
*/
useStringBuffer?: boolean
/**
* @default 1024
*/
maxCharLength?: number
/**
* @default [LPMSG, LPSTR, LPWSTR, LPTSTR, LPWORD ]
*/
CharDefs?: Def[]
}
import {
_POINTER,
StructInstanceBase,
LPTSTR,
ACCESS_MASK,
DWORD,
WCHAR_String,
} from '../common.types.js'

@@ -20,3 +20,3 @@

*/
pDatatype: LPTSTR
pDatatype: WCHAR_String
/**

@@ -49,7 +49,10 @@ * Pointer to a DEVMODE structure that identifies the default environment and initialization data for a printer.

Flags: DWORD
pDescription: LPTSTR
pName: LPTSTR
pComment: LPTSTR
pDescription: WCHAR_String
pName: WCHAR_String
pComment: WCHAR_String
// pDescription: LPTSTR
// pName: LPTSTR
// pComment: LPTSTR
}
export type PPRINTER_INFO_1 = _POINTER

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc